<template>
<h1>猜数字练习</h1>
  <h3>请输入一个1-100之间的整数</h3>
  <input   v-model="number">
  <button @click="check()">验证</button>
  <h4>小提示:{{result}} </h4>
</template>


<script setup>
  import {ref} from "vue";

  const number = ref('');
  const result = ref('')
  let temp = parseInt( Math.random()*100+1);
  console.log("小抄"+temp);
  let num=0;
  const check= ()=>{
    num++;
    // 读取双向绑定的变量需要在后边添加.value获取属性值
    if (number.value>temp){
      result.value='猜大了'
    }
    if (number.value<temp){
      result.value='猜小了'
    }
    if (number.value == temp){
      result.value="恭喜你猜了"+num+"次猜对了"
    }
  }

</script>

<style scoped>

</style>